package cn.cmkj.auction.data.http;

import org.json.JSONArray;
import org.json.JSONObject;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import cn.cmkj.auction.app.Urls;

/**
 * Created by cunguoyao on 2018/1/29.
 */

public class ShuhuaImage implements Serializable {

    public String l_url;
    public String m_url;
    public String s_url;

    public static ShuhuaImage parseFromJson(JSONObject json, boolean needAddUrlHead) {
        if(json != null) {
            ShuhuaImage image = new ShuhuaImage();
            if(needAddUrlHead) {
                image.l_url = Urls.web + "/" + json.optString("l_url", "");
                image.m_url = Urls.web + "/" + json.optString("m_url", "");
                image.s_url = Urls.web + "/" + json.optString("s_url", "");
            }else {
                image.l_url = json.optString("l_url", "");
                image.m_url = json.optString("m_url", "");
                image.s_url = json.optString("s_url", "");
            }
            return image;
        }
        return null;
    }

    public static List<ShuhuaImage> parseJsonArray(JSONArray array, boolean needAddUrlHead) {
        List<ShuhuaImage> list = new ArrayList<>();
        if(array != null && array.length() > 0){
            for(int i=0;i<array.length();i++){
                list.add(parseFromJson(array.optJSONObject(i), needAddUrlHead));
            }
        }
        return list;
    }
}
